package com.gobi.config.profile;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.ConfigurableEnvironment;

import java.util.Arrays;

/**
 * @author Porter.YY
 * 2019/6/27.
 */

@Configuration
public class ProfileConfig {

    public static final String PROD = "prod";

    /**
     * 当选择prod profile 时，该dev环境不会初始化
     *
     * @return
     */
    @Bean
    @Profile("dev")
    public DemoBean dev() {
        System.out.println("dev init ...");
        return new DemoBean("dev");
    }

    @Bean
    @Profile(PROD)
    public DemoBean prod() {
        System.out.println("prod init ...");
        return new DemoBean(PROD);
    }

    @Bean
    public ProfileConfig test(ConfigurableEnvironment environment) {

        System.out.println(environment.acceptsProfiles(PROD));
        System.out.println(Arrays.toString(environment.getDefaultProfiles()));
        System.out.println(Arrays.toString(environment.getActiveProfiles()));

        System.out.println(environment.getSystemProperties());
        System.out.println(environment.getSystemEnvironment());
        return new ProfileConfig();
    }

}
